<template>
    <div>
        <!-- <DoctorHome></DoctorHome> -->
        <UserHome></UserHome>
        <Auth v-if="modalVisible" :changeModalType="changeModalType" @getUserInfo = "getUserInfo" @getPhoneNumber = "getPhoneNumber" :changeBtnType="changeBtnType"></Auth>
    </div>
</template>
<script>
import Auth from '../../common/auth';
import api from '../../config/api/index'
import { post } from '../../utils/request'
import doctorHome from '../../components/Doctor/doctorHome'
import userHome from '../../components/User/userHome'
import { getSetting, getUserInfo, setStorageSync, getStorageSync, getOpenId } from '../../utils/wechatAuth';
export default {
    data () {
        return {
            changeBtnType: 'login',
            modalVisible: true
        }
    },
    components: {
        Auth,
        DoctorHome: doctorHome,
        UserHome: userHome
    },
    methods: {
        getUserInfo() {
            getUserInfo((userInfo) => {
                setStorageSync('userInfo' , userInfo)
                const openId = getStorageSync('openId')
                if (!openId || openId.length === 0) {
                    console.log('openId is null')
                    getOpenId(userInfo).then(res => {
                        this.changeBtnType = 'phone'
                    })
                }
            })
        },
        getSetting() {
            getSetting('userInfo', () => {console.log('success')}, () => {console.log('fail')})
        },
        getPhoneNumber() {
            console.log('getPhoneNumber')
            post(api.register,{
                mobile: "18686894183"
            }).then(res => console.log(res))
        },
        changeModalType () {
            this.modalVisible = false
            wx.showTabBar()
        }
    },
    created() {
        if (getStorageSync('token') !== '') {
            this.modalVisible = false
        }
    }
}
</script>

<style lang="scss" scoped>

</style>